package com.sk.bilibili.view.fragment.member;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.member.home.FollowThemAdapter;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.callBack.ThemClickCallBack;
import com.sk.bilibili.model.fragment.member.FollowThemModel;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class FollowThemFragment extends BaseRefreshFragment<FollowThemModel> implements ThemClickCallBack {

    private Integer memberId;

    public FollowThemFragment(Integer memberId) {
        this.memberId=memberId;
    }

    private FollowThemAdapter followThemAdapter;

    @Override
    public void onRefresh() {
        model.refresh(memberId);
    }

    @Override
    public void onBottom() {
        model.loadMore(memberId);
    }

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        followThemAdapter = new FollowThemAdapter(getContext(), this);
        adapter.addAdapter(followThemAdapter);
    }

    @Override
    public void onThemClick(Integer themId, int selection) {
        ThemActivity.start(getContext(),themId,selection);
    }

    public void refreshSuccess(List<FollowThem> records) {
        followThemAdapter.setData(records);
        cancelRefresh();
    }

    public void loadMoreSuccess(List<FollowThem> records) {
        if(records.isEmpty()){
            toast("没有更多数据了");
        }else {
            followThemAdapter.addData(records);
        }
    }

}